package com.yutian.tomcatservlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//继承于HttpServlet
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("处理Get()请求...");
        PrintWriter out =response.getWriter();
        //指定文件的输出类型
        response.setContentType("text/html;charset=utf-8");
        out.println("<strong>Hello Servlet with doGet!</strong><br>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("处理Post()请求...");
        PrintWriter out =response.getWriter();
        //指定文件的输出类型
        response.setContentType("text/html;charset=utf-8");
        out.println("<strong>Hello Servlet with doPost!</strong><br>");
    }

}
